package com.mak001.lite.multiSkill;

import java.util.ArrayList;

import extras.mak001.Time;
import com.rsbuddy.event.events.MessageEvent;

public abstract class subScript {
	private boolean stop = false;
	/**
	 * the loop of the subScript
	 */
	public abstract void execute();
	
	public void loop(){
		if(!stop)
			execute();
	}
	
	public void stop(){
		stop = true;
	}

	/**
	 * the required item ids
	 */
	public abstract int[] required();

	/**
	 * allows script to switch at an appropriate time
	 */
	public abstract boolean canSwitch();

	/**
	 * gets the skill that the subScript is running(26 is no skill)
	 */
	public abstract int skill();

	/**
	 * gets the current state of the subScript
	 */
	public abstract String getStatus();

	/**
	 * message listener
	 */
	public abstract void messageRecieved(MessageEvent e);

	/**
	 * Use this to declare the String[]
	 * 
	 * @return the String[] to paint
	 * 
	 * @see #getPaintString()
	 */
	public abstract String[] paintString();

	/**
	 * Puts a cap on the String[] length. The cap is 7. Use this to actually
	 * draw the String[]
	 * 
	 * @return the String[] to paint
	 * 
	 * @see #paintString()
	 */
	public String[] getPaintString() {
		ArrayList<String> s = new ArrayList<String>();
		if (paintString() != null)
			for (int i = 0; i < paintString().length; i++) {
				if (i < 8)
					s.add(paintString()[i]);
			}
		else
			s.add("");
		return toStringArray(s);
	}

	private String[] toStringArray(ArrayList<String> list) {
		String[] ret = new String[list.size()];
		int i = 0;
		for (String e : list)
			ret[i++] = e;
		return ret;
	}

	public void sleep(int i) {
		MainLite.sleep(i);
	}

	public void sleep(int i, int j) {
		MainLite.sleep(i, j);
	}

	/**
	 * You can use this for XP/Hour and GP/Hour calculations.<p>
	 * 
	 * Please do not pause, resume or reset
	 * it in the subScript. The core takes care of it.
	 * 
	 * @return time the specific subScript has been running
	 */
	public abstract Time getTime();

}
